Page({
    data: {
        exists: wx.getStorageSync('exists'),

        //头部导航栏高度(因为导航栏和二级菜单用的是fixed定位)
        wxBaiHeight: Number(wx.getStorageSync('wxBarHeight')),
        //二级菜单高度（因为导航栏和二级菜单用的是fixed定位）
        submenu: Number(wx.getStorageSync('submenu')),


        title: ["疾病自诊", "百科全书", "专家问诊"],
        // 小程序只分普通用户和专家（管理员在小程序也算普通用户）
        status: 1,
        mgs: "疾病自诊",
        select: [1, 0, 0]
    },
    onLoad: function (options) {

        if (options.selectIndex == 1) {
            this.chance1()
        } else if (options.selectIndex == 2) {
            this.chance2()
        } else if (options.selectIndex == 3) {
            this.chance3()
        }

        let username = wx.getStorageSync('username')
        wx.request({
            url: `http://120.77.156.205:8808/wx/ucenter/status/${username}`,
            header: {
                'content-type': 'application/json;charset=UTF-8'
            },
            success: (res) => {
                if (res.data.code == 0) {
                    let status = res.data.data.status
                    if (status == 2) {
                        this.setData({
                            title: ["给鱼看病", "百科全书", "专家信息"],
                            status: 2,
                            mgs: "给鱼看病"
                        })
                    } else {
                        this.setData({
                            title: ["疾病自诊", "百科全书", "专家问诊"],
                            status: 1,
                            mgs: "疾病自诊"
                        })
                    }
                    console.log(res.data.data.status)
                }
                console.log(res)
            }
        })
    },
    chance1() {
        if (this.data.status == 1) {
            this.setData({
                select: [1, 0, 0],
                mgs: "疾病自诊"
            })
        } else {
            this.setData({
                select: [1, 0, 0],
                mgs: "给鱼看病"
            })
        }
    },
    chance2() {
        if (this.data.status == 1) {
            this.setData({
                select: [0, 1, 0],
                mgs: "百科全书"
            })
        } else {
            this.setData({
                select: [0, 1, 0],
                mgs: "百科全书"
            })
        }
    },
    chance3() {
        if (this.data.status == 1) {
            this.setData({
                select: [0, 0, 1],
                mgs: "专家问诊"
            })
        } else {
            this.setData({
                select: [0, 0, 1],
                mgs: "专家信息"
            })
        }
    },

    onReachBottom: function () {
        if (this.data.select[1] == 1) {
            let encyclopedia = this.selectComponent("#encyclopedia")
            encyclopedia.onReachBottom()
        }else if(this.data.select[2]==1){
            if(this.data.status ==1){
                let expert_consultation = this.selectComponent("#expert_consultation")
                expert_consultation.onReachBottom()
            }
           
        }

    }
})